package com.galaxy.user.controller;

import com.galaxy.common.core.domain.R;
import com.galaxy.common.mybatis.core.page.PageQuery;
import com.galaxy.common.mybatis.core.page.TableDataInfo;
import com.galaxy.user.domain.UserBase;
import com.galaxy.user.domain.bo.UserBaseBo;
import com.galaxy.user.domain.vo.UserBaseVo;
import com.galaxy.user.service.UserBaseService;
import com.galaxy.user.domain.convert.UserBaseConvert;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@RestController
@RequestMapping("/user")
public class UserController {

    private final UserBaseService userBaseService;
    private final UserBaseConvert userBaseConvert;

    @SaCheckPermission("user:user:list")
    @GetMapping("/list")
    public TableDataInfo<UserBaseVo> list(UserBaseBo bo, PageQuery pageQuery) {
        return userBaseService.queryPageList(bo, pageQuery);
    }

    @SaCheckPermission("user:user:query")
    @GetMapping("/{id}")
    public R<UserBaseVo> getInfo(@PathVariable Long id) {
        UserBase userBase = userBaseService.queryById(id);
        return R.ok(userBaseConvert.convertVo(userBase));
    }

    @SaCheckPermission("user:user:add")
    @PostMapping
    public R<Boolean> add(@RequestBody UserBaseBo bo) {
        return R.ok(userBaseService.insertByBo(bo));
    }

    @SaCheckPermission("user:user:edit")
    @PutMapping
    public R<Boolean> edit(@RequestBody UserBaseBo bo) {
        return R.ok(userBaseService.updateByBo(bo));
    }

    @SaCheckPermission("user:user:remove")
    @DeleteMapping("/{ids}")
    public R<Boolean> remove(@PathVariable List<Long> ids) {
        return R.ok(userBaseService.deleteWithValidByIds(ids, true));
    }
}
